import 'dart:ui';

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_app/utils/shared_preferences.dart';
import 'package:flutter_app/utils/application.dart';

class LocaleProvider extends ChangeNotifier {
  final List<Locale> supportedLocales = const <Locale>[
    Locale('zh', 'CN'),
    Locale('en', 'US')
  ];

  Locale get locale {
    final String locale =
        Application.sharePreference.getString(SharedPreferencesKeys.Locale);
    switch (locale) {
      case 'zh':
        return supportedLocales[0];
      case 'en':
        return supportedLocales[1];
      default:
        return null;
    }
  }

  void setLocale(String locale) {
    print("locale = $locale");
    Application.sharePreference.putString(SharedPreferencesKeys.Locale, locale);
    notifyListeners();
  }
}
